/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ec.edu.espe.ccsoft.mantenimiento.dao;

import ec.edu.espe.ccsoft.mantenimiento.modelos.Rol;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaQuery;

/**
 *
 * @author misahaelfernandez
 */
@Stateless
public class RolFacade extends AbstractFacade<Rol> {

    @PersistenceContext(unitName = "ec.edu.espe.ccsoft_CCSoftMantenimiento-ejb_ejb_1PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public RolFacade() {
        super(Rol.class);
    } 
    
    public Rol findByNombre(String nombre){
        
        CriteriaQuery consulta =this.em.getCriteriaBuilder().createQuery();
        consulta.where(this.em.getCriteriaBuilder().equal(consulta.from(Rol.class).get("nombre"), nombre));
       
        return em.createQuery(consulta).getResultList().isEmpty() ? null : (Rol) em.createQuery(consulta).getSingleResult();
    }
}
